Page({
  data: {
    weight: 0,
    height: 0,
    bmiResult: '',
    bmiCategory: ''
  },
  onWeightInput: function(e) {
    this.setData({
      weight: parseFloat(e.detail.value) || 0
    });
  },
  onHeightInput: function(e) {
    this.setData({
      height: parseFloat(e.detail.value) || 0
    });
  },
  calculateBMI: function() {
    const { weight, height } = this.data;
    if (weight > 0 && height > 0) {
      const bmi = weight / Math.pow((height / 100), 2);
      this.setData({
        bmiResult: `BMI: ${bmi.toFixed(2)}`,
        bmiCategory: this.getBmiCategory(bmi)
      });
    } else {
      this.setData({
        bmiResult: '',
        bmiCategory: '请输入有效的体重和身高'
      });
    }
  },
  getBmiCategory: function(bmi) {
    if (bmi < 18.5) return '偏瘦';
    else if (bmi >= 18.5 && bmi <= 24) return '正常';
    else if (bmi > 24 && bmi <= 28) return '偏胖';
    else return '肥胖';
  }
});